package com.xiaoma.verbal.web.admin;

import com.xiaoma.verbal.service.QuCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Owner on 2015/5/20.
 */
@Controller
@RequestMapping("/test/qu_course")
public class QuCourseAct {

    @Autowired
    private QuCourseService quCourseService;

    @RequestMapping(value = "/import", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> importFile(@RequestParam(value = "excelData", required = false) MultipartFile file, String fileType){
        Map<String, Object> result = new HashMap<String, Object>();

        InputStream fis = null;

        int status = 1;

        try {
            fis = file.getInputStream();
            int version = 2007;
            if (fileType != null && fileType.length() > 0 && fileType.equals("xls")) {
                version = 2003;
            }
            status = quCourseService.importData(version, fis);
        } catch (Exception e) {
            e.printStackTrace();
            status = 3;
            result.put("message",e.getMessage());
        }
        result.put("result", status);

        return result;

    }
}
